package com.test;

import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.sqlite.SQLiteDataSource;

import com.hewep.kit.CacheKit;
import com.hewep.kit.ConfigKit;
import com.hewep.kit.TableKit;
import com.hewep.support.PoiKit;
import com.hewep.support.excel.DefaultRowReader;
import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.dialect.Sqlite3Dialect;

public class Client {
	@Before
	public void init(){
		String dbPath = PathKit.getWebRootPath()+"/data/tool.db";
		String dbUrl = "jdbc:sqlite:"+dbPath;
		SQLiteDataSource ds = new SQLiteDataSource();
		ds.setUrl(dbUrl);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(ds);
		arp.setDialect(new Sqlite3Dialect());
		arp.start();
	}
	@Test
	public void test(){
		System.out.println("12.3".contains("."));
		String str = ConfigKit.getStr("excel", "");
		String columns = TableKit.getColumns("org_temp");
		String sql1 = TableKit.getInsertSql("org_temp");
		String[] split = TableKit.getColumns("datas").split(",");
		System.out.println(TableKit.getColumns("datas"));
	}
	public static void main(String[] args) {
		
		String dbPath = PathKit.getWebRootPath()+"/data/tool.db";
		String dbUrl = "jdbc:sqlite:"+dbPath;
		SQLiteDataSource ds = new SQLiteDataSource();
		ds.setUrl(dbUrl);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(ds);
		arp.setDialect(new Sqlite3Dialect());
		arp.start();
		
		Integer i = 1;
		System.out.println(i.toString());
		List<Record> records = Db.find("select * from config");
		for (Record record : records) {
			String tableName = record.getStr("item");
			String columns = record.getStr("value");
			String columnRemark = record.getStr("key_value");
			String remarkColumn = record.getStr("value_key");
			CacheKit.cacheByTableName(tableName, CacheKit.COLUMN_REMARK, columnRemark);
			CacheKit.cacheByTableName(tableName, CacheKit.REMARK_COLUMN, remarkColumn);
			CacheKit.cacheByTableName(tableName, CacheKit.COLUMNS, columns);
		}
		records = Db.find("select * from org  ");
		String tempFilePath = PathKit.getWebRootPath() + "\\upload\\datas.xlsx";
		try {
			PoiKit.writeExcel("", CacheKit.getColumns("org"), records);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
